<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>档案归还</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>档案归还明细</span></div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th>档案名称</th>
                            <th>档案编号</th>
                            <th>借阅日期</th>
                            <th>借阅份数</th>
                            <th><text>*</text>返还日期</th>
                            <th><text>*</text>接收人</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    var param_ids = getQueryVariable('ids') || 0;

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_dang_jie_fan, data:{ids:param_ids}}).done(function(res){
            if (res.code === 2000) {


                var list = res.data.list;
                for (var key in list){
                    var str = '';
                    var nums = parseInt(key)+1;
                    str += '<tr>';
                    str += '<td style="width: 45px">'+nums+'</td>';
                    str += '<td><input type="text" listid="'+list[key].id+'" readonly class="layui-input name disabled" value="'+list[key].name+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input number disabled" value="'+list[key].number+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input jiedt disabled" value="'+list[key].jiedt+'"></td>';
                    str += '<td><input type="text" readonly class="layui-input num disabled" value="'+list[key].num+'"></td>';
                    str += '<td><input type="text" class="layui-input fandt bdate_ymd" value="'+list[key].fandt+'" readonly></td>';
                    str += '<td><input type="text" class="layui-input shouer" value="'+list[key].shouer+'"></td>';
                    str += '</tr>';
                    $("#list_list").append(str);
                }

                render_date();
                render_from();
                initParseMoney();
            }
        });


        form.on('submit(add)', function(data){
            parseMoney(data);

            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var id = $(this).find('.name').attr('listid');
                    var fandt = $(this).find('.fandt').val();
                    var shouer = $(this).find('.shouer').val();

                    var index = i + 1;
                    if(!fandt){
                        throw new Error('第'+index+'行，请选择返还日期');
                    }
                    if(!shouer){
                        throw new Error('第'+index+'行，请输入接收人');
                    }


                    list.push({
                        id:id,
                        fandt:fandt,
                        shouer:shouer,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;



            facade.ajax({url: ask_dang_jie_fan, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });




</script>
</body>
</html>
